#!/usr/bin/env python
#coding=utf-8
#File: callback.py

import re
import string

text = "a line of text\\012another line of the text\\012etx..."

def octal(match):
    # replace octal code with corresponding ASCII character
    # print match.groups()
    return chr(string.atoi(match.groups()[0], 8))

octal_pattern = re.compile(r"\\(\d\d\d)")

print text
print octal_pattern.sub(octal, text)